<template>
	<view>
		<van-card v-for="item in list" :key="item.goods_id" :num="item.goods_number" :price="item.goods_price"
			:title="item.goods_name" :thumb="item.goods_small_logo" :thumb-link="'/sub/detail/detail?id='+item.goods_id" />
		<view class="" style="text-align: center; background-color: #eee;" v-show="pagenum>=count">到底了，亲</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list: [],
				cid: '', //分类id
				pagenum: 1,
				pagesize: 10,
				count: 0 //总页数
			};
		},
		onLoad(e) {
			console.log(e)
			this.cid = e.cid
			this.getList()
		},
		methods: {
			async getList() {
				let {
					data: res
				} = await uni.$http.get(
					`/api/public/v1/goods/search?cid=${this.cid}&pagenum=${this.pagenum}&pagesize=${this.pagesize}`
				)
				console.log(res, 'list')
				this.list = [...this.list, ...res.message.goods]
				this.count = Math.ceil(res.message.total / this.pagesize)
			},
		},
		onPullDownRefresh() {
			this.list = []
			this.pagenum = 1
			this.getList()
		},
		onReachBottom() {
			this.pagenum += 1
			if (this.pagenum <= this.count) {
				this.getList()
			}
		}
	}
</script>

<style lang="scss">

</style>
